import wepy from 'wepy'
import cates from '../../assets/cates.js'

export default class Home extends wepy.mixin {
  data = {
    // 全部分类数据
    cates: [],
    activeKey: 0,
    // 二级分类数据
    secondCate: []
  }

  config = {
  }

  methods = {
    // 监听侧边导航发生变化
    sidebarChange (e) {
      this.secondCate = this.cates[e.detail].children
    }
  }

  // 获取分类数据
  async getCateList () {
    // 上线注释打开
    // const {data: res} = await wepy.get('/categories')
    // 上线注释掉
    const res = cates
    if(res.meta.status !== 200) return wepy.baseToast()
    this.cates = res.message
    this.secondCate = res.message[0].children
    this.$apply()
  }

  onLoad () {
    this.getCateList()
  }
}